import React, { Component } from "react";
import MyNavBar from "../../compoents/MyNavBar";
import { connect } from "react-redux";
import MyLongList from "../../compoents/MyLongList";
import { update } from "../../redux/actions/getCurCity_action";
import { Toast } from "antd-mobile";

class CityList extends Component {
  NavigationRouteGoBact = () => {
    this.props.history.goBack();
  };

  changCityMsg = (city) => {
    // TODO 应该先判断是否又房源

    if (city.label === "上海") {
      localStorage.setItem("cache_city_msg", JSON.stringify(city));
      this.props.history.goBack();
    } else {
      Toast.fail("客观不要慌，此地暂无房源", 2);
    }
  };

  render() {
    const { curCity } = this.props;
    return (
      <div style={{ height: "100%", paddingTop: "45px" }}>
        {/* 导航看 */}
        <MyNavBar
          navBarName={"城市列表"}
          NavigationRouteGoBact={this.NavigationRouteGoBact}
        />
        {/* 长列表 */}

        <MyLongList
          curCity={curCity}
          changCityMsg={this.changCityMsg}
        ></MyLongList>
      </div>
    );
  }
}

export default connect(
  (state) => {
    return { curCity: state.curCity };
  },
  {
    updateCity: update,
  }
)(CityList);
